For Each |
|
For Each is a BPMN group construct and represents Activities or sub-processes that should be executed for each sub part of a message. The For Each loop uses a counter, known as an iterator to specify the number of times the same sequence of activities should be repeated. For Each is graphically represented as follows:
The iterator has the following three numeric values:
- Initial iterator value
- Incremental value
- Execute Condition
The loop ends when the execute condition fails. The XPath of the recursive element should be copied in the Message Map for this construct to work.
Example of a For Each Loop
Consider the case of a HR Manager who wants to view the employee records of the first five employees. When the manager reaches the fifth record, the process of fetching employee records stops.
The above example can be modeled as follows:
Incremental value = iterator value +1
All employee records will be fetched till the iterator count reaches the fifth record, after which the process stops.
Consider an example of a filter condition in the For Each loop:
'/ns2:GetEmployeesOutput/ns2:GetEmployeesResponse/ns2:tuple/ns2:old/ns2:Employees[ns2:TitleOfCourtesy = 'Ms.']'. Here the loop is not iterated for all the records in the response, but only for those records which have the value 'Ms.' in the element 'TitleOfCourtesy'.
Since you have defined a filter for these records, you must not use the complete path (' ns2:GetEmployeesOutput/ns2:GetEmployeesResponse/ns2:tuple/ns2:old/ns2:Employees/ ns2:TitleOfCourtesy ') for the assignment within the For Each construct. You must always use the iterator name, for example, /instance:iterator_o_34/ns2:TitleOfCourtesy/text(). Alternatively, you can use the entire path with the filter (' /ns2:GetEmployeesOutput/ns2:GetEmployeesResponse/ns2:tuple/ns2:old/ns2:Employees[ns2:TitleOfCourtesy = 'Ms.'] '). This is because the filter used in the For Each loop filters records that have the value 'Ms.' in the elementTitleOfCourtesy. When you use the entire path without the filter in the assignment, it considers the entire set of records without the filter. However, the assignment will not work for records which do not meet the filter condition, hence you must always use the iterator name as a reference for the filter condition or use the complete path with the filter.